home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / GLUT / test / test16.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  3KB  |  141 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. /* Exercise all the GLUT shapes. */
  9.  
  10. #ifdef __sgi
  11. #include <malloc.h>
  12. #endif
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <unistd.h>
  16. #include <GL/glut.h>
  17.  
  18. GLfloat light_diffuse[] =
  19. {1.0, 0.0, 0.0, 1.0};
  20. GLfloat light_position[] =
  21. {1.0, 1.0, 1.0, 0.0};
  22. GLUquadricObj *qobj;
  23.  
  24. void
  25. displayFunc(void)
  26. {
  27.   static int shape = 1;
  28.  
  29.   fprintf(stderr, " %d", shape);
  30.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  31.   switch (shape) {
  32.   case 1:
  33.     glutWireSphere(1.0, 20, 20);
  34.     break;
  35.   case 2:
  36.     glutSolidSphere(1.0, 20, 20);
  37.     break;
  38.   case 3:
  39.     glutWireCone(1.0, 1.0, 20, 20);
  40.     break;
  41.   case 4:
  42.     glutSolidCone(1.0, 1.0, 20, 20);
  43.     break;
  44.   case 5:
  45.     glutWireCube(1.0);
  46.     break;
  47.   case 6:
  48.     glutSolidCube(1.0);
  49.     break;
  50.   case 7:
  51.     glutWireTorus(0.5, 1.0, 15, 15);
  52.     break;
  53.   case 8:
  54.     glutSolidTorus(0.5, 1.0, 15, 15);
  55.     break;
  56.   case 9:
  57.     glutWireDodecahedron();
  58.     break;
  59.   case 10:
  60.     glutSolidDodecahedron();
  61.     break;
  62.   case 11:
  63.     glutWireTeapot(1.0);
  64.     break;
  65.   case 12:
  66.     glutSolidTeapot(1.0);
  67.     break;
  68.   case 13:
  69.     glutWireOctahedron();
  70.     break;
  71.   case 14:
  72.     glutSolidOctahedron();
  73.     break;
  74.   case 15:
  75.     glutWireTetrahedron();
  76.     break;
  77.   case 16:
  78.     glutSolidTetrahedron();
  79.     break;
  80.   case 17:
  81.     glutWireIcosahedron();
  82.     break;
  83.   case 18:
  84.     glutSolidIcosahedron();
  85.     break;
  86.   default:
  87.     printf("\nPASS: test16\n");
  88.     exit(0);
  89.   }
  90.   glutSwapBuffers();
  91.   shape += 1;
  92.   sleep(1);
  93.   glutPostRedisplay();
  94. }
  95.  
  96. void
  97. timefunc(int value)
  98. {
  99.   printf("\nFAIL: test16\n");
  100.   exit(1);
  101. }
  102.  
  103. int
  104. main(int argc, char **argv)
  105. {
  106. #if defined(__sgi)  && !defined(REDWOOD)
  107.   /* XXX IRIX 6.0.1 mallopt(M_DEBUG, 1) busted. */
  108.   mallopt(M_DEBUG, 1);
  109. #endif
  110.   glutInit(&argc, argv);
  111.   glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
  112.   glutCreateWindow("test16");
  113.   glutDisplayFunc(displayFunc);
  114.  
  115.   qobj = gluNewQuadric();
  116.   gluQuadricDrawStyle(qobj, GLU_FILL);
  117.   glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  118.   glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  119.   glEnable(GL_LIGHTING);
  120.   glEnable(GL_LIGHT0);
  121.   glEnable(GL_DEPTH_TEST);
  122.   glMatrixMode(GL_PROJECTION);
  123.   gluPerspective( /* field of view in degree */ 22.0,
  124.   /* aspect ratio */ 1.0,
  125.     /* Z near */ 1.0, /* Z far */ 10.0);
  126.   glMatrixMode(GL_MODELVIEW);
  127.   gluLookAt(0.0, 0.0, 5.0,  /* eye is at (0,0,5) */
  128.     0.0, 0.0, 0.0,      /* center is at (0,0,0) */
  129.     0.0, 1.0, 0.);      /* up is in postivie Y direction */
  130.   glTranslatef(0.0, 0.0, -3.0);
  131.   glRotatef(25, 1.0, 0.0, 0.0);
  132.  
  133.   /* Have a reasonably large timeout since some machines make
  134.      take a while to render all those polygons. */
  135.   glutTimerFunc(35000, timefunc, 1);
  136.  
  137.   fprintf(stderr, "shape =");
  138.   glutMainLoop();
  139.   return 0;             /* ANSI C requires main to return int. */
  140. }
  141.